import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/model/pay_model/list_bank_hf_model.dart';
import 'package:yysk_app/net/api/pay_url.dart';
import 'package:yysk_app/net/http.dart';
import 'package:yysk_app/utils/js_tool.dart';

class SelectBankListController extends GetxController {
  var nameController = TextEditingController();
   var banks = RxList<ListBankHfModel>();
    var filteredBanks = RxList<ListBankHfModel>();
  var type = 'add'.obs;  //add 添加 ，withdrawal 提现 ，order 订单
  @override
  void onInit() {
    super.onInit();
     type.value = Get.parameters['type'] ?? Get.arguments['type'];
    getBankList();
    nameController.addListener(() {
      final query = nameController.text.toLowerCase();
      if (query.isEmpty) {
          // ignore: invalid_use_of_protected_member
          filteredBanks.value = banks.value;
        } else {
          filteredBanks.value =
              // ignore: invalid_use_of_protected_member
              banks.value
                  .where((bank) => bank.bankName!.toLowerCase().contains(query))
                  .toList();
        }
    });
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
    nameController.dispose();
  }
  // 银行卡列表

  Future<void> getBankList() async {
    http.netFetch<List<ListBankHfModel>>(
      PayUrl.listBank,
      params: {
    "channel": "HUIFU",
    "plat": "USER"
},
      method: Method.post,

      success: (r) {
        banks.addAll(r.data??[]);
         filteredBanks.addAll(r.data??[]);
        consoleLog('${banks.length}');
        return r;
      },
    );
  }
  
 
}
